import { getCheckGroupList, getCheckGroupUpdate, getSetTurnTime, setTurnTime, getHeroTurnStatus, getAutoNewTime } from '../../../vuex/action'

export default {
  name: 'hero-rank',
  data() {
    return {
      playTime: 0,
      nowPlayTime: '0分钟',
      showNote: false,
      lists: [],
      checkTime: null,
      turnIcon: 0
    }
  },
  vuex: {
    actions: {
      xGetCheckGroupList: getCheckGroupList,
      xGetCheckGroupUpdate: getCheckGroupUpdate,
      xGetSetTurnTime: getSetTurnTime,
      xGetHeroTurnStatus: getHeroTurnStatus,
      xSetTurnTime: setTurnTime,
      xGetAutoNewTime: getAutoNewTime
    }
  },
  methods: {
    checkFormat() {
      let reg = /\d+/g
      if (reg.test(this.playTime)) {
        this.nowPlayTime = this.playTime + '分钟'
        this.showNote = false
      } else {
        this.showNote = true
        window.setTimeout(() => {
          this.showNote = false
        }, 3000)
      }
      this.setTurnTime()
    },
    getList() {
      this.xGetCheckGroupList({
        type: 5
      })
        .then((data) => {
          this.checkTime = data.rankAudit
          this.lists = data.list
        })
    },
    getTurnStatus() {
      this.xGetHeroTurnStatus()
        .then((data) => {
          this.turnIcon = data.auto
          console.log(this.turnIcon)
        })
    },
    getTurnTime() {
      this.xGetSetTurnTime()
        .then((data) => {
          console.log(data)
          this.playTime = data.time
          this.nowPlayTime = this.playTime + '分钟'
          this.turnIcon = data.auto
        })
    },
    setTurnTime() {
      this.xSetTurnTime({
        loopTime: this.playTime
      })
        .then((data) => {
        })
    },
    showHide(list) {
      list.status = list.status === 0 ? 1 : 0
      this.xGetCheckGroupUpdate({
        type: list.type,
        refId: list.refId,
        status: list.status
      })
        .then((data) => {
        })
    },
    check() {
      this.xGetAutoNewTime({
        type: 5
      })
        .then((data) => {
          this.checkTime = data.data.rankAudit
          window.location.reload()
        })
    }
  },
  ready() {
    this.getList()
    this.getTurnTime()
  }
}
